package org.htmlparser.nodes;

import java.io.Serializable;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.lexer.Page;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import org.htmlparser.visitors.NodeVisitor;

public abstract class AbstractNode
  implements Node, Serializable
{
  protected NodeList children;
  protected Page mPage;
  protected int nodeBegin;
  protected int nodeEnd;
  protected Node parent;

  public AbstractNode(Page paramPage, int paramInt1, int paramInt2)
  {
    this.mPage = paramPage;
    this.nodeBegin = paramInt1;
    this.nodeEnd = paramInt2;
    this.parent = null;
    this.children = null;
  }

  public abstract void accept(NodeVisitor paramNodeVisitor);

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }

  public void collectInto(NodeList paramNodeList, NodeFilter paramNodeFilter)
  {
    if (paramNodeFilter.accept(this))
      paramNodeList.add(this);
  }

  public void doSemanticAction()
    throws ParserException
  {
  }

  public NodeList getChildren()
  {
    return this.children;
  }

  public int getEndPosition()
  {
    return this.nodeEnd;
  }

  public Node getFirstChild()
  {
    Node localNode;
    if (this.children == null)
      localNode = null;
    while (true)
    {
      while (true)
      {
        return localNode;
        if (this.children.size() != 0)
          break;
        localNode = null;
      }
      localNode = this.children.elementAt(0);
    }
  }

  public Node getLastChild()
  {
    Node localNode;
    if (this.children == null)
      localNode = null;
    while (true)
    {
      int i;
      while (true)
      {
        return localNode;
        i = this.children.size();
        if (i != 0)
          break;
        localNode = null;
      }
      localNode = this.children.elementAt(i - 1);
    }
  }

  public Node getNextSibling()
  {
    Node localNode2;
    Node localNode1 = getParent();
    if (localNode1 == null)
      localNode2 = null;
    while (true)
    {
      NodeList localNodeList;
      int j;
      while (true)
      {
        int i;
        while (true)
        {
          while (true)
          {
            return localNode2;
            localNodeList = localNode1.getChildren();
            if (localNodeList != null)
              break;
            localNode2 = null;
          }
          i = localNodeList.size();
          if (i >= 2)
            break;
          localNode2 = null;
        }
        j = -1;
        int k = 0;
        while (true)
        {
          while (true)
          {
            if (k < i)
            {
              if (localNodeList.elementAt(k) != this)
                break;
              j = k;
            }
            if (j != -1)
              break label94;
            localNode2 = null;
          }
          ++k;
        }
        label94: if (j != i - 1)
          break;
        localNode2 = null;
      }
      localNode2 = localNodeList.elementAt(j + 1);
    }
  }

  public Page getPage()
  {
    return this.mPage;
  }

  public Node getParent()
  {
    return this.parent;
  }

  public Node getPreviousSibling()
  {
    Node localNode2;
    Node localNode1 = getParent();
    if (localNode1 == null)
      localNode2 = null;
    while (true)
    {
      NodeList localNodeList;
      int i;
      while (true)
      {
        while (true)
        {
          return localNode2;
          localNodeList = localNode1.getChildren();
          if (localNodeList != null)
            break;
          localNode2 = null;
        }
        i = localNodeList.size();
        if (i >= 2)
          break;
        localNode2 = null;
      }
      int j = -1;
      int k = 0;
      while (true)
      {
        while (true)
        {
          if (k < i)
          {
            if (localNodeList.elementAt(k) != this)
              break;
            j = k;
          }
          if (j >= 1)
            break label93;
          localNode2 = null;
        }
        ++k;
      }
      label93: localNode2 = localNodeList.elementAt(j - 1);
    }
  }

  public int getStartPosition()
  {
    return this.nodeBegin;
  }

  public String getText()
  {
    return null;
  }

  public void setChildren(NodeList paramNodeList)
  {
    this.children = paramNodeList;
  }

  public void setEndPosition(int paramInt)
  {
    this.nodeEnd = paramInt;
  }

  public void setPage(Page paramPage)
  {
    this.mPage = paramPage;
  }

  public void setParent(Node paramNode)
  {
    this.parent = paramNode;
  }

  public void setStartPosition(int paramInt)
  {
    this.nodeBegin = paramInt;
  }

  public void setText(String paramString)
  {
  }

  public String toHtml()
  {
    return toHtml(false);
  }

  public abstract String toHtml(boolean paramBoolean);

  public abstract String toPlainTextString();

  public abstract String toString();
}